/*!
   @file   QuadraticBrush.cpp
   @author Ben Herila (ben@herila.net)
   @author Evan Wallace (evan.exe@gmail.com)
   @date   Fall 2010

   @brief Implementation of a brush with a quadratic mask distribution.
   You should fill this file in while completing the Brush assignment.

*/

#include "QuadraticBrush.h"

QuadraticBrush::QuadraticBrush(BGRA color, int flow, int radius) : Brush(color, flow, radius)
{
    // @TODO: [BRUSH] You'll probably want to set up the mask right away.
    makeMask();
}

QuadraticBrush::~QuadraticBrush()
{
    // @TODO: [BRUSH] Delete any resources owned by this brush, so you don't leak memory.

}

void QuadraticBrush::makeMask()
{
    // @TODO: [BRUSH] Set up the mask for your Quadratic brush here...
    for (int i = -m_radius; i<= m_radius; i++)
        for(int j = -m_radius; j <= m_radius; j++){
        double distance = sqrt(double(i*i+j*j));
        if(distance > m_radius){
            m_mask[(i+3)*(2*m_radius+1)+j+3] = 0;
        }
        else{
            double m_radius = double(m_radius);
            m_mask[(i+3)*(2*m_radius+1)+j+3] = (distance-m_radius)*(distance-m_radius)/(m_radius*m_radius);
        }
    }

}


